<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Element</title>
<script type="text/javascript">
	function appendToBody(element) {
		
		if (element.parentNode.id == 'container') {
			var target = document.getElementById("targetDiv");
			target.appendChild(element);
		} else {
			var target = document.getElementById("container");
			target.appendChild(element);
		}
	}
</script>
</head>
<body>
	<div id="container" style="border: 5px solid black; height: 100px;">
		<button onclick="appendToBody(this);"> 1번 </button>
		<button onclick="appendToBody(this);"> 2번 </button>
		<button onclick="appendToBody(this);"> 3번 </button>
	</div>
	<div id="targetDiv" style="border: 1px solid black; height: 100px;"></div>
</body>
</html>
